package com.iiixxxiii.pf.api.kafka;
 
import org.apache.kafka.clients.producer.ProducerRecord;
import java.util.Date;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
/**
 * kafka测试类 生产者
 *
 */
public class TestKafkaProducer {
  public static void main(String[] args) throws InterruptedException, ExecutionException {
        //添加生产者
        KafkaPlugin p = new KafkaPlugin(KafkaTools.defaultName, "127.0.0.1:9092", "org.apache.kafka.common.serialization.StringSerializer", "org.apache.kafka.common.serialization.StringSerializer");
        p.start();
        for (int i = 0; i < 10; i++) {
            TimeUnit.SECONDS.sleep(1);
            //模拟发送消息
            Future f = KafkaTools.send(KafkaTools.defaultName, new ProducerRecord<String, String>("test.topic", "keykey", "msgmsg中文消息啊" + new Date()));
            f.get();
        }
        p.stop();
    }
}
